package com.easy.common.util;

import java.util.HashMap;

public class ResultData extends HashMap {
    //code  msg   data
    public ResultData() {
    }
    public ResultData(String code,String msg,Object data) {
        this.put("code", code);
        this.put("msg", msg);
        this.put("data", data);
    }
    public ResultData(Object... objs){
        for(int i=0;i<objs.length;i+=2){
            this.put(objs[i], objs[i+1]);
        }
    }
    public ResultData(String code,String msg,String data,Object... objs) {
        this.put("code", code);
        this.put("msg", msg);
        this.put("data", data);
        for(int i=0;i<objs.length;i+=2){
            this.put(objs[i], objs[i+1]);
        }
    }


    public static ResultData success(){
        return new ResultData("code",200,"msg","操作成功");
    }

    public static ResultData success(String code,String msg,Object data){
        return new ResultData(code,msg,data);
    }
    public static ResultData success(String msg,Object data){
        return new ResultData("code",200,msg,data);
    }
    public static ResultData success(Object data){
        return new ResultData("code",200,"操作成功",data);
    }
    public static ResultData success(Object... data){
        return new ResultData(data);
    }
    public static ResultData fail500(String msg){
        return new ResultData("code","500","msg",msg);
    }
    public static ResultData fail500(){
        return new ResultData("code","500","msg","系统异常请联系管理员");
    }
    public static ResultData fail400(String msg){
        return new ResultData("code","400","msg",msg);    }
    public static ResultData fail400(){
        return new ResultData("code","400","msg","请求异常");
    }
    public static ResultData fail(String msg){
        return new ResultData("code","202","msg",msg);
    }
    public static ResultData fail(){
        return new ResultData("code","202","msg","请求失败");
    }

}
